package org.crud4j.core;


/**
 * Field definition
 */
public class CrudFieldDef {

	/**
	 * Field type
	 */
	private Class type;

	/**
	 * Field name
	 */
	private String name;

	/**
	 * Field label
	 */
	private String label;

	/**
	 * Field editor
	 */
	private String editor;

	/**
	 * Position of the field in the browse page
	 */
	private Integer position = Integer.MAX_VALUE;

	/**
	 * Flag that indicates whether this field is browsable
	 */
	private boolean browsable;

	/**
	 * Flag that indicates whether this field is the ID of the bean
	 */
	private boolean id;

	/**
	 * Flag that indicates whether empty values should be saved as null or empty
	 * strings
	 */
	private boolean respectEmptyValue;

	/**
	 * Flag that indicates whether this field is a remove mark
	 */
	private boolean removeMark;

	/**
	 * Flag that indicates whether this field is editable
	 */
	private boolean editDisabled = false;

	/**
	 * Flag that indicates whether this field is editable on creation
	 */
	private boolean newDisabled = false;

	/**
	 * Flag that indicates whether this field is filter to browse the bean
	 */
	private boolean browseFilter;

	/**
	 * Flag that indicates whether this field should be hidden
	 */
	private boolean hidden;

	/**
	 * Length of the field
	 */
	private Integer length = 255;

	/**
	 * Flag that indicates whether this field supports null values
	 */
	private boolean nullable = true;

	/**
	 * Flag that indicates whether this field contains a crud bean
	 */
	private boolean crudBean;

	/**
	 * Flag that indicates whether the fiel value is generated by the crud
	 * framework
	 */
	private boolean generatedValue = false;

	/**
	 * Regular expresion for client validation (javascript)
	 */
	private String validationExpression = null;

	/**
	 * Message for error validation
	 */
	private String validationMessage = null;

	/**
	 * Class that corresponds to the id of this field
	 */
	private Class crudFkClass;

	/**
	 * Flag that indicates whether this field refers to a crud foreign key
	 */
	private boolean crudFk;

	public boolean isBrowsable() {
		return browsable;
	}

	public void setBrowsable(boolean browsable) {
		this.browsable = browsable;
	}

	public boolean isBrowseFilter() {
		return browseFilter;
	}

	public void setBrowseFilter(boolean browseFilter) {
		this.browseFilter = browseFilter;
	}

	public boolean isGeneratedValue() {
		return generatedValue;
	}

	public void setGeneratedValue(boolean generatedValue) {
		this.generatedValue = generatedValue;
	}

	public boolean isHidden() {
		return hidden;
	}

	public void setHidden(boolean hidden) {
		this.hidden = hidden;
	}

	public boolean isId() {
		return id;
	}

	public void setId(boolean id) {
		this.id = id;
		this.nullable = false;
	}

	public String getLabel() {
		if (label == null) {
			return this.name;
		}
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isNullable() {
		return nullable;
	}

	public void setNullable(boolean nullable) {
		this.nullable = nullable;
	}

	public Integer getPosition() {
		return position;
	}

	public void setPosition(Integer position) {
		this.position = position;
	}

	public boolean isRemoveMark() {
		return removeMark;
	}

	public void setRemoveMark(boolean removeMark) {
		this.removeMark = removeMark;
	}

	public boolean isRespectEmptyValue() {
		return respectEmptyValue;
	}

	public void setRespectEmptyValue(boolean respectEmptyFieldValue) {
		this.respectEmptyValue = respectEmptyFieldValue;
	}

	public Class getType() {
		return type;
	}

	public void setType(Class type) {
		this.type = type;
	}

	public String getValidationExpression() {
		return validationExpression;
	}

	public void setValidationExpression(String validationExpression) {
		this.validationExpression = validationExpression;
	}

	public String getValidationMessage() {
		return validationMessage;
	}

	public void setValidationMessage(String validationMessage) {
		this.validationMessage = validationMessage;
	}

	public boolean isCrudBean() {
		return crudBean;
	}

	public void setCrudBean(boolean crudBean) {
		this.crudBean = crudBean;
	}

	public String getEditor() {
		return editor;
	}

	public void setEditor(String editor) {
		this.editor = editor;
	}

	public Class getCrudFkClass() {
		return crudFkClass;
	}

	public void setCrudFkClass(Class crudFkClass) {
		this.crudFkClass = crudFkClass;
	}

	public boolean isCrudFk() {
		return crudFk;
	}

	public void setCrudFk(boolean crudFk) {
		this.crudFk = crudFk;
	}

	public boolean isEditDisabled() {
		return editDisabled;
	}

	public void setEditDisabled(boolean editDisabled) {
		this.editDisabled = editDisabled;
	}

	public boolean isNewDisabled() {
		return newDisabled;
	}

	public void setNewDisabled(boolean newDisabled) {
		this.newDisabled = newDisabled;
	}

}
